/**
 * 版权所有 2009-2015 中国中医科学院中医药信息研究所 何前锋 frontpeak@yahoo.com.cn
 **/
package cn.ac.cintcm.sh.domain;

public class NameValue {
    
    private static final String FIELD_SPLITER = ":";
    private String name;
    private float value; 
    
    public NameValue(String n, float value) {
        this.name = n;
        this.value = value;
    }
    
    public NameValue(String s) {
        if (s != null) {
            String[] v = s.split(FIELD_SPLITER);
            if (v.length == 2) {
                this.name = v[0];
                this.value = Float.valueOf(v[1]);
            }
        }
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final NameValue other = (NameValue) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        return true;
    }
    public float getValue() {
        return value;
    }
    public void setValue(float value) {
        this.value = value;
    }
    
    public String toString() {
        return name + FIELD_SPLITER + value;
    }
    
}